<?php
namespace app\index\controller;
use think\Controller;
use think\Request;

class Index extends Controller
{
    /**
     * 首页
     */
    public function index(){
    	//banner
    	$ban = db('index_banner')->where("id=1")->find();
		$banner['logo'] = IMG_PATH.$ban['images'];
		$banner['back_images'] = IMG_PATH.$ban['images_bj'];
		$banner['title'] = $ban['title'];
		$banner['des']   = $ban['des'];
		$this->assign("banner",$banner);
		//分类
		$type = db('index_type')->order("id asc")->select();
		for ($i=0; $i < count($type); $i++) { 
			$type[$i]['images'] = IMG_PATH.$type[$i]['images'];
		}
		$this->assign("type",$type);
		//版块介绍
		$introduce = db('index_introduce')->select();
		for ($e=0; $e < count($introduce); $e++) { 
			$introduce[$e]['images'] = IMG_PATH.$introduce[$e]['images'];
		}
		$this->assign("int",$introduce);
		//底部图片
		$foot = db('index_banner')->where("id=2")->find();
		$foot['logo'] = IMG_PATH.$foot['images'];
		$foot['back_images'] = IMG_PATH.$foot['images_bj'];
		$this->assign("foot",$foot);
		//新闻分类
		$news = db('news_type')->select();
		for ($n=0; $n < count($news); $n++) { 
			$news[$n]['images'] = IMG_PATH.$news[$n]['images'];
		}
		$this->assign("news",$news);
		//新闻列表
		$listone = db('news')->where("type=1")->order('sort desc')->select();
		$this->assign("one",$listone);
		$listtwo = db('news')->where("type=2")->order('sort desc')->select();
		$this->assign("two",$listtwo);
		$listthree = db('news')->where("type=3")->order('sort desc')->select();
		$this->assign("three",$listthree);
		
        return $this->fetch();
    }
    
    //查询商品详情和知食详情
    public function goods_knowledge_info(){
    	$type = input('type');
    	$id = input('id');

    	if($type == 'goods_info'){
    		$content = db('goods')->where(array('id'=>$id))->field('content')->find();
    	}

    	if($type == 'foods_knowledge_info'){
    		$content = db('foods_knowledge')->where(array('id'=>$id))->field('content')->find();
    	}

    	if(empty($content)){
    		$content['content'] = '';
    	}

    	$this->assign("content",$content['content']);
    	return $this->fetch();
    }
}
